/*-- Rucksack --*/

#strict 2

#include GEAR

local pClonk, c, user, pBearer, OverID;
/*--------------------------------------------Callbacks-------------------------------------------------------*/

func IsHazardGear() { return(true); }
func GetGearType()  { return(GEAR_Backpack); }
func ConUseable()   { return(true); }
func ConDesc()      { return("$OpenBackpack$"); }   

/*--------------------------------------------Weiter-----------------------------------------------------------*/

func ConUse(object pUser)
{
 pClonk = pUser;
  CreateMenu(CXIV, pUser, this(), 0, 0, 0, 1, 0);
  
    AddMenuItem(Format("$PutBackpack$"), "Put(pClonk)", CXIV, pUser);
     AddMenuItem(Format("$Takebackpack$"), "Take(pClonk)", CXIV, pUser);
} 

func Put(object pUser) 
{
 pClonk = pUser;
 
  CreateMenu(CXIV, pUser, this(), 0, 0, 0, 1, 0);
    
   if(!Contents(0, pClonk)) return(1);
    AddMenuItem(Format("$PutObj$", GetName(Contents(0, pClonk))), "PutObj(Contents(0, pClonk))", GetID(Contents(0, pClonk)), pUser);
     if(!Contents(1, pClonk)) return(1);
      AddMenuItem(Format("$PutObj$", GetName(Contents(1, pClonk))), "PutObj(Contents(1, pClonk))", GetID(Contents(1, pClonk)), pUser);
       if(!Contents(2, pClonk)) return(1); 
        AddMenuItem(Format("$PutObj$", GetName(Contents(2, pClonk))), "PutObj(Contents(2, pClonk))", GetID(Contents(2, pClonk)), pUser);
         if(!Contents(3, pClonk)) return(1); 
          AddMenuItem(Format("$PutObj$", GetName(Contents(3, pClonk))), "PutObj(Contents(3, pClonk))", GetID(Contents(3, pClonk)), pUser);
           if(!Contents(4, pClonk)) return(1); 
            AddMenuItem(Format("$PutObj$", GetName(Contents(4, pClonk))), "PutObj(Contents(4, pClonk))", GetID(Contents(4, pClonk)), pUser);     
}

 
func PutObj(object pObj)
{
if(ContentsCount() < 30)
 {
  pObj-> Enter(this());
 }
 Put(pClonk);
}
 
func Take(object pUser)
{ 
 pClonk = pUser;
  var i; 
  
  CreateMenu(CXIV, pUser, this(), 0, 0, 0, 1, 0);
   


if(ContentsCount() == 0) return(1);

 AddMenuItem(Format("$TakeObj$", GetName(Contents(0))), "TakeObj(Contents(0))", GetID(Contents(0)), pUser, ContentsCount(GetID(Contents(0))));
 i++;
 
  if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(1))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++;
   if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(2))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
    if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(3))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
     if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(4))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
      if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(5))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
       
        if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(6))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
         if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(7))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
          if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(8))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
           if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(9))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
            if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(10))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
            
             if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(11))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
              if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(12))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
               if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(13))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(14))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                 if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(15))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                 
                  if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(16))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                   if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(17))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                    if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(18))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                     if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(19))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                      if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(20))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                      
                       if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(21))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                        if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(22))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                         if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(23))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                          if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(24))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                           if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(25))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++;
                            
                            if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(26))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++;    
                             if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(27))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                              if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(28))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++; 
                               if (CheckDoubles(i))    AddMenuItem(Format("$TakeObj$", GetName(Contents(i))), "TakeObj(Contents(29))", GetID(Contents(i)), pUser, ContentsCount(GetID(Contents(i))));   i++;                                                                      
} 
      
 
func CheckDoubles(int i)

{

 if (GetID(Contents( 0)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 1) return(true);
  if (GetID(Contents( 1)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 2) return(true);
   if (GetID(Contents( 2)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 3) return(true);
    if (GetID(Contents( 3)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 4) return(true);
     if (GetID(Contents( 4)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 5) return(true);
      
 if (GetID(Contents( 5)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 6) return(true);
  if (GetID(Contents( 6)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 7) return(true);
   if (GetID(Contents( 7)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 8) return(true);
    if (GetID(Contents( 8)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 9) return(true);
     if (GetID(Contents( 9)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 10) return(true);
      
 if (GetID(Contents(10)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 11) return(true);
  if (GetID(Contents(11)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 12) return(true);
   if (GetID(Contents(12)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 13) return(true);
    if (GetID(Contents(13)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 14) return(true);
     if (GetID(Contents(14)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 15) return(true);
      
if (GetID(Contents(15)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 16) return(true);   
 if (GetID(Contents(16)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 17) return(true);
  if (GetID(Contents(17)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 18) return(true);
   if (GetID(Contents(18)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 19) return(true);
    if (GetID(Contents(19)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 20) return(true);
    
if (GetID(Contents(20)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 21) return(true);
 if (GetID(Contents(21)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 22) return(true);  
  if (GetID(Contents(22)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 23) return(true);
   if (GetID(Contents(23)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 24) return(true);
    if (GetID(Contents(24)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 25) return(true);
     
if (GetID(Contents(25)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 26) return(true);    
 if (GetID(Contents(26)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 27) return(true);
  if (GetID(Contents(27)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 28) return(true);
   if (GetID(Contents(28)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 29) return(true);
    if (GetID(Contents(29)) == GetID(Contents(i))) return(false); if(Contents(i) == 0) return(false); if(i == 30) return(true);

} 
 




func TakeObj(object pObj)
{
if(CheckClonkContents(pObj))
{
pObj-> Enter(pClonk);
 if(pObj ->~ IsWeapon()) pClonk -> SetAction("WalkArmed");
}
 Take(pClonk);
}


func CheckClonkContents(object pObj)
{
 var c;
  var idObj = GetID(pObj);

 if(!ContentsCount(0, pClonk)) return(1);

 if(pObj ->~ IsAmmoPacket())
 {
  if(!CustomContentsCount("IsAmmoPacket"))  return(1);
   if(CustomContentsCount("IsAmmoPacket"))  return(0);
 }

  
 if(pObj ->~ IsWeapon()) 
 {
   {
    if(ContentsCount(idObj, pClonk) || CustomContentsCount("IsWeapon") >= 3)
     return(0); 
    if(ContentsCount(idObj, pClonk) == 0 || CustomContentsCount("IsWeapon") < 3)
     return(1);   
   }
 }
   
if(!(pObj ->~ IsWeapon() && pObj->~ IsAmmoPacket()))
 {
c = ObjectCount2(Find_Container(pClonk), Find_Not(Find_Func("IsWeapon"), Find_Func("IsAmmoPacket")));
 if(c < 2) return(1); else return(0);
 }

}

public func CustomContentsCount(string funcname)
{

  for(var i=0,j,obj ; obj = Contents(i, pClonk) ; i++)
    if(ObjectCall(obj, funcname))
      j++;
      
  return(j);
}


func GearEffect(object pHazard)
{
OverID = 2;
pBearer = pHazard;
 SetGraphics(0, pHazard, RA01, OverID, GFXOV_MODE_Base); 
  AddEffect("Draw", this, 101, 1, this, RA01); 
}


func GearEffectReset(object pHazard)
{
 SetGraphics(0, pHazard, 0, OverID); 
  RemoveEffect("Draw", this);
}


func FxDrawTimer(object pTarget)
{
var x;

if(!GetDir(pBearer)) x = 1;
 if(GetDir(pBearer)) x = -1;

if(GetAction(pBearer) == "AimSquat" || GetAction(pBearer) == "AimSquatLow")
 {
  var iPhase = GetPhase(pBearer);
 
 if(iPhase == 0) { SetObjDrawTransform(800, -500*x, 5200*x, +500*x, 800, 2000, pBearer, OverID);  return 1; }
  if(iPhase == 1) { SetObjDrawTransform(800, -400*x, 5100*x, +400*x, 800, 2000, pBearer, OverID);  return 1; }
   if(iPhase == 2) { SetObjDrawTransform(850, -275*x, 5000*x, +275*x, 850, 2000, pBearer, OverID);  return 1; }
    if(iPhase == 3) { SetObjDrawTransform(900, -150*x, 5000*x, +150*x, 900, 2000, pBearer, OverID);  return 1; }
     if(iPhase == 4) { SetObjDrawTransform(900, -000*x, 5000*x, +000*x, 900, 2000, pBearer, OverID);  return 1; }
      if(iPhase == 5) { SetObjDrawTransform(900, +100*x, 5000*x, -100*x, 900, 2000, pBearer, OverID);  return 1; }
       if(iPhase == 6) { SetObjDrawTransform(900, +200*x, 5000*x, -200*x, 900, 2000, pBearer, OverID);  return 1;  }
  }
  SetObjDrawTransform(900, 0, 5000*x, 0, 900, -1000, pBearer, OverID);
} 
 

